package com.jiangjiang.eshop.pay.api.impl;

import com.jiangjiang.eshop.common.help.DateHelper;
import com.jiangjiang.eshop.pay.api.PayApi;
import com.jiangjiang.eshop.pay.api.QueryPayStatusResponse;
import com.jiangjiang.eshop.pay.constant.PayTransactionStatus;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.UUID;

/**
 * @Author Jianghaowen
 * @Date 2021/9/28
 * @Description: TODO
 * @Version V1.0
 **/
@Service
public class PayApiImpl implements PayApi {

    @Autowired
    private DateHelper dateHelper;

    @Override

    public String getQrCode(Integer transactionChannel, String orderNo, Double totalAmount) throws Exception {
        return UUID.randomUUID().toString().replace("-", "");
    }

    @Override
    public QueryPayStatusResponse queryPayStatus(Integer transactionChannel, String orderNo) throws Exception {
        // 根据交易渠道选择调用支付宝或者微信支付的远程接口，根据订单号去查询支付状态
        // 接口里需要判断，当前支付的一个状态
        QueryPayStatusResponse response = new QueryPayStatusResponse();
        response.setUserPayAccount(UUID.randomUUID().toString().replace("-", ""));
        response.setTransactionNumber(UUID.randomUUID().toString().replace("-", ""));
        response.setResponseCode("SUCCESS");
        response.setFinishPayTime(dateHelper.getCurrentDate());
        response.setPayTransactionStatus(PayTransactionStatus.SUCCESS);

        return response;
    }

    @Override
    public Boolean refund(Integer transactionChannel, String orderNo, Double refundAmount) throws Exception {
        // 根据交易渠道选择支付宝或者微信的api接口，去发送请求，申请退款
        // 根据退款的结果判断来返回true或者false
        // true就代表退款成功了，false就代表退款失败了
        return true;
    }
}
